<template>
  <div class="testCheck">
    <Tabs type="card" @on-click="tabclick" value="tb1">
      <TabPane name="tb1" label="UD45"></TabPane>
      <TabPane name="tb2" label="MTU"></TabPane>
    </Tabs>
    <div class="searchDiv">
      <Form :model="searchItem" :label-width="90">
        <Row :gutter="10">
          <Col span="6">
            <FormItem label="电站">
              <Select v-model="searchItem.powerStation" clearable filterable @on-change="getHd">
                <Option
                  v-for="(item, index) in powerStationList"
                  :value="item"
                  :key="index"
                >{{ item }}</Option>
              </Select>
            </FormItem>
          </Col>
          <Col span="6">
            <FormItem label="HD编号">
              <Select
                v-model="searchItem.hdNumber"
                clearable
                filterable
                :disabled="HBnumberList.length == 0"
                @on-change="getJz"
              >
                <Option v-for="(item, index) in HBnumberList" :value="item" :key="index">{{ item }}</Option>
              </Select>
            </FormItem>
          </Col>
          <Col span="6">
            <FormItem label="机组编号">
              <Select
                v-model="searchItem.aircrewNumber"
                clearable
                filterable
                :disabled="JZnumberList.length == 0"
              >
                <Option v-for="(item, index) in JZnumberList" :value="item" :key="index">{{ item }}</Option>
              </Select>
            </FormItem>
          </Col>
          <Col span="6">
            <FormItem label="参数名称">
              <Select v-model="searchItem.analyzeParam">
                <Option v-for="(item, index) in mainCode" :value="item.key">
                  {{
                  item.name
                  }}
                </Option>
              </Select>
            </FormItem>
          </Col>
          <Col span="6">
            <FormItem label="时间">
              <DatePicker
                type="daterange"
                @on-change="changeTime"
                :value="timearry"
                :options="options2"
                placement="bottom-end"
                placeholder="请选择时间范围"
                style="width:100%"
              ></DatePicker>
            </FormItem>
          </Col>
          <Col span="12">
            <Button type="primary" class="marRight" @click="addJz">加入对比</Button>
            <Button type="primary" class="marRight" @click="add">录入数据</Button>
            <Upload
              style="float:left;"
              :headers="fileheader"
              :on-success="fileSuccess"
              :show-upload-list="false"
              :action="apihost + '/admin-api/admins/checkoutRecord/udUpload'"
            >
              <Button type="info" class="marRight">导入EXcel</Button>
            </Upload>
            <Button type="success" @click="download">导出Excel</Button>
          </Col>
        </Row>
      </Form>
      <div v-if="tagList1.length > 0" style="margin-bottom:10px;">
        <Tag
          type="border"
          color="primary"
          v-for="item in tagList1"
          :key="item"
          :name="item"
          closable
          @on-close="handleClose1"
        >{{ item }}</Tag>
      </div>
    </div>
    <div id="myChart" style="width:100%;height:500px;border-top:1px solid #ccc;padding-top:10px;"></div>
    <Table :loading="loading" border="" :columns="columns" :data="tableData"></Table>
    <Page
      show-total
      :total="total"
      :current="pageNo"
      :page-size="pageSize"
      style="margin:20px auto;text-align:center"
      @on-change="changePage"
    />
    <!-- 新增弹窗开始 -->
    <Modal :mask-closable="false" v-model="modal1" :title="title1" width="900">
      <Form :label-width="75">
        <Row class="xzjz">
          <Col span="6">
            <FormItem :model="formItem" label="电站">
              <Select v-model="formItem.powerStation" clearable filterable @on-change="getHd">
                <Option
                  v-for="(item, index) in powerStationList"
                  :value="item"
                  :key="index"
                >{{ item }}</Option>
              </Select>
            </FormItem>
          </Col>
          <Col span="6">
            <FormItem label="HD编号">
              <Select
                v-model="formItem.hdNumber"
                clearable
                filterable
                :disabled="HBnumberList.length == 0"
                @on-change="getJz"
              >
                <Option v-for="(item, index) in HBnumberList" :value="item" :key="index">{{ item }}</Option>
              </Select>
            </FormItem>
          </Col>
          <Col span="6">
            <FormItem label="机组编号">
              <Select
                v-model="formItem.aircrewNumber"
                clearable
                filterable
                :disabled="JZnumberList.length == 0"
              >
                <Option v-for="(item, index) in JZnumberList" :value="item" :key="index">{{ item }}</Option>
              </Select>
            </FormItem>
          </Col>
          <Col span="6">
            <FormItem label="大修号">
              <Input v-model="formItem.overhaulNo" size="small" placeholder="请输入"></Input>
            </FormItem>
          </Col>
        </Row>
        <Row class="xzjz">
          <Col span="6">
            <FormItem label="巡检时间">
              <DatePicker
                type="datetime"
                v-model="formItem.checkTime"
                @on-change="time"
                format="yyyy-MM-dd HH:mm:ss"
                placeholder="选择日期"
                style="width: 100%"
              ></DatePicker>
            </FormItem>
          </Col>
        </Row>
      </Form>
      <div style="height:600px;overflow:auto;">
        <table width="100%" class="maintb">
          <tr>
            <th>项目</th>
            <th>监测内容</th>
            <th>名称</th>
            <th>参考值</th>
            <th>输入值</th>
          </tr>
          <tr>
            <td rowspan="4">油位</td>
            <td>001MO</td>
            <td>150LN</td>
            <td>最高-20mm＜L＜最高</td>
            <td>
              <Input v-model="formItem.mo001" size="small" placeholder="请输入"></Input>
            </td>
          </tr>
          <tr>
            <td>002MO</td>
            <td>650LN</td>
            <td>最高-20mm＜L＜最高</td>
            <td>
              <Input v-model="formItem.mo002" size="small" placeholder="请输入"></Input>
            </td>
          </tr>
          <tr>
            <td>910GA</td>
            <td>001MO</td>
            <td>中线＜L＜最高</td>
            <td>
              <Input v-model="formItem.ga001mo910" size="small" placeholder="请输入"></Input>
            </td>
          </tr>
          <tr>
            <td>910GA</td>
            <td>002MO</td>
            <td>中线＜L＜最高</td>
            <td>
              <Input v-model="formItem.ga002mo910" size="small" placeholder="请输入"></Input>
            </td>
          </tr>
          <tr>
            <td rowspan="10">设备运行状况</td>
            <td>001MO电加热器</td>
            <td>200RS</td>
            <td>记录运行时间</td>
            <td>
              <Input v-model="formItem.moDptc001" size="small" placeholder="请输入"></Input>
            </td>
          </tr>
          <tr>
            <td>002MO电加热器</td>
            <td>700RS</td>
            <td>记录运行时间</td>
            <td>
              <Input v-model="formItem.moDptc002" size="small" placeholder="请输入"></Input>
            </td>
          </tr>
          <tr>
            <td>001MO循环水泵</td>
            <td>201PO</td>
            <td>记录运行时间</td>
            <td>
              <Input v-model="formItem.moPump001" size="small" placeholder="请输入"></Input>
            </td>
          </tr>
          <tr>
            <td>002MO循环水泵</td>
            <td>701PO</td>
            <td>记录运行时间</td>
            <td>
              <Input v-model="formItem.moPump002" size="small" placeholder="请输入"></Input>
            </td>
          </tr>
          <tr>
            <td>001MO预润滑油泵</td>
            <td>152PO</td>
            <td>记录运行时间</td>
            <td>
              <Input v-model="formItem.moOilPump001" size="small" placeholder="请输入"></Input>
            </td>
          </tr>
          <tr>
            <td>002MO预润滑油泵</td>
            <td>652PO</td>
            <td>记录运行时间</td>
            <td>
              <Input v-model="formItem.moOilPump002" size="small" placeholder="请输入"></Input>
            </td>
          </tr>
          <tr>
            <td>250CO启动次数</td>
            <td>441QM</td>
            <td>启动次数</td>
            <td>
              <Input v-model="formItem.coStartups250" size="small" placeholder="请输入"></Input>
            </td>
          </tr>
          <tr>
            <td>251CO启动次数</td>
            <td>442QM</td>
            <td>启动次数</td>
            <td>
              <Input v-model="formItem.coStartups251" size="small" placeholder="请输入"></Input>
            </td>
          </tr>
          <tr>
            <td>750CO启动次数</td>
            <td>471QM</td>
            <td>启动次数</td>
            <td>
              <Input v-model="formItem.coStartups750" size="small" placeholder="请输入"></Input>
            </td>
          </tr>
          <tr>
            <td>751CO启动次数</td>
            <td>472QM</td>
            <td>启动次数</td>
            <td>
              <Input v-model="formItem.coStartups751" size="small" placeholder="请输入"></Input>
            </td>
          </tr>
          <tr>
            <td rowspan="2">阀门</td>
            <td>001MO预润滑流量限制阀</td>
            <td>162VH</td>
            <td>回油管热时为正常</td>
            <td>
              <Input v-model="formItem.moFlowValve001" size="small" placeholder="请输入"></Input>
            </td>
          </tr>
          <tr>
            <td>002MO预润滑流量限制阀</td>
            <td>662VH</td>
            <td>回油管热时为正常</td>
            <td>
              <Input v-model="formItem.moFlowValve002" size="small" placeholder="请输入"></Input>
            </td>
          </tr>
          <tr>
            <td rowspan="5">液体记录</td>
            <td>燃油储存罐001BA</td>
            <td>001ID</td>
            <td>L>80%</td>
            <td>
              <Input v-model="formItem.tank001ba" size="small" placeholder="请输入"></Input>
            </td>
          </tr>
          <tr>
            <td>燃油日用罐002BA</td>
            <td>002ID</td>
            <td>L>80%</td>
            <td>
              <Input v-model="formItem.fuel_tank002ba" size="small" placeholder="请输入"></Input>
            </td>
          </tr>
          <tr>
            <td>润滑油储存罐006BA</td>
            <td>003ID</td>
            <td>L>70%</td>
            <td>
              <Input v-model="formItem.storageTank006ba" size="small" placeholder="请输入"></Input>
            </td>
          </tr>
          <tr>
            <td>冷却水罐200BA</td>
            <td>004ID</td>
            <td>L>70%</td>
            <td>
              <Input v-model="formItem.coolingWater200ba" size="small" placeholder="请输入"></Input>
            </td>
          </tr>
          <tr>
            <td>冷却水罐700BA</td>
            <td>005ID</td>
            <td>L>70%</td>
            <td>
              <Input v-model="formItem.coolingWater700ba" size="small" placeholder="请输入"></Input>
            </td>
          </tr>
          <tr>
            <td rowspan="4">入口油温</td>
            <td>001MO A端入口油温</td>
            <td>150LT</td>
            <td>52℃＜T＜70℃</td>
            <td>
              <Input v-model="formItem.moATemperature001" size="small" placeholder="请输入"></Input>
            </td>
          </tr>
          <tr>
            <td>001MO B端入口油温</td>
            <td>152LT</td>
            <td>52℃＜T＜70℃</td>
            <td>
              <Input v-model="formItem.moBTemperature001" size="small" placeholder="请输入"></Input>
            </td>
          </tr>
          <tr>
            <td>002MO A端入口油温</td>
            <td>650LT</td>
            <td>52℃＜T＜70℃</td>
            <td>
              <Input v-model="formItem.moATemperature002" size="small" placeholder="请输入"></Input>
            </td>
          </tr>
          <tr>
            <td>002MO B端入口油温</td>
            <td>652LT</td>
            <td>52℃＜T＜70℃</td>
            <td>
              <Input v-model="formItem.moBTemperature002" size="small" placeholder="请输入"></Input>
            </td>
          </tr>
          <tr>
            <td rowspan="6">冷却水温度</td>
            <td>001MO 冷却水入口温度</td>
            <td>200LT</td>
            <td>57℃＜T＜80℃</td>
            <td>
              <Input v-model="formItem.moCoolingInletTemp001" size="small" placeholder="请输入"></Input>
            </td>
          </tr>
          <tr>
            <td>001MO 冷却水出口温度</td>
            <td>203LT</td>
            <td>57℃＜T＜80℃</td>
            <td>
              <Input v-model="formItem.moCoolingExitTemp001" size="small" placeholder="请输入"></Input>
            </td>
          </tr>
          <tr>
            <td>002MO 冷却水入口温度</td>
            <td>700LT</td>
            <td>57℃＜T＜80℃</td>
            <td>
              <Input v-model="formItem.moCoolingInletTemp002" size="small" placeholder="请输入"></Input>
            </td>
          </tr>
          <tr>
            <td>002MO 冷却水出口温度</td>
            <td>703LT</td>
            <td>57℃＜T＜80℃</td>
            <td>
              <Input v-model="formItem.moCoolingExitTemp002" size="small" placeholder="请输入"></Input>
            </td>
          </tr>
          <tr>
            <td>柴油机冷却剂入口压力</td>
            <td>200LP</td>
            <td>≈1.2bar</td>
            <td>
              <Input v-model="formItem.dieselInletPressure200" size="small" placeholder="请输入"></Input>
            </td>
          </tr>
          <tr>
            <td>柴油机冷却剂入口压力</td>
            <td>700LP</td>
            <td>≈1.2bar</td>
            <td>
              <Input v-model="formItem.dieselInletPressure700" size="small" placeholder="请输入"></Input>
            </td>
          </tr>
          <tr>
            <td>压力</td>
            <td>250/251/750/751BBA</td>
            <td></td>
            <td>35＜P＜40bar</td>
            <td>
              <Input v-model="formItem.pressure" size="small" placeholder="请输入"></Input>
            </td>
          </tr>
        </table>
        <Form :label-width="75" style="margin-top:15px;">
          <FormItem label="异常记录">
            <Input v-model="formItem.abnormalRecord" type="textarea" placeholder="请输入"></Input>
          </FormItem>
        </Form>
      </div>
      <div slot="footer">
        <Button @click="modal1 = false">取消</Button>
        <Button type="primary" :loading="btnClick" @click="ok">确定</Button>
      </div>
    </Modal>
    <Modal
      :mask-closable="false"
      v-model="delmodal1"
      width="360"
      class-name="vertical-center-modal"
      @on-ok="remove()"
    >
      <p slot="header" style="color:#f60;text-align:center">
        <Icon type="ios-information-circle"></Icon>
        <span>确认删除</span>
      </p>
      <div style="text-align:center">
        <p>确认删除此数据么？</p>
      </div>
    </Modal>
    <!-- 新增弹窗结束 -->
  </div>
</template>

<script>
import {
  getSelectOption,
  getAllPeople,
  getTime,
  getAllEqu,
} from "@/api/select";
import {
  getTableData,
  add,
  update,
  del,
  exp,
  echart,
  imp,
} from "@/api/testCheck";
import { getToken } from "@/libs/util";
export default {
  data() {
    return {
      btnClick: false,
      loading: true,

      delmodal1: false,
      delId1: 0,
      peopleList: [],
      powerStationList: [],
      allEquList: [],
      allEquList2: [],
      timearry: [],
      options2: {
        shortcuts: [
          {
            text: "最近一周",
            value() {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              return [start, end];
            },
          },
          {
            text: "最近一月",
            value() {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              return [start, end];
            },
          },
          {
            text: "最近三月",
            value() {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              return [start, end];
            },
          },
        ],
      },

      HBnumberList: [],
      JZnumberList: [],
      modal1: false,
      title1: "新增记录",
      pageNo: 1,
      pageSize: 10,
      total: 0,
      fileheader: {
        Authorization: "Bearer " + (getToken() ? getToken() : ""),
      },
      colorarry: [
        "#c12e34",
        "#e6b600",
        "#0098d9",
        "#2b821d",
        "#005eaa",
        "#339ca8",
        "#a134d4",
        "#32a487",
        "#eb1e99",
        "#ff8819",
      ],
      searchItem: {
        powerStation: "",
        hdNumber: "",
        aircrewNumber: "",
        analyzeParam: "mo001",
        startTime: "",
        endTime: "",
      },
      formItem: {
        recordName: localStorage.getItem("recordUserName"),
        recordId: localStorage.getItem("recordUserId"),
        recordTime: getTime(),
      },
      columns: [
        {
          type: "index",
          width: 60,
          title: "序号",
          align: "center",
        },
        {
          title: "电站",
          key: "powerStation",
        },
        {
          title: "机组编号",
          key: "aircrewNumber",
        },
        {
          title: "检查日期",
          key: "checkTime",
        },
        {
          title: "记录人",
          key: "recordName",
        },
        {
          title: "记录时间",
          key: "recordTime",
          width: 150,
        },
        {
          title: "操作",
          key: "action",
          width: 150,
          align: "center",
          render: (h, params) => {
            return h("div", [
              h(
                "Button",
                {
                  props: {
                    type: "primary",
                    size: "small",
                  },
                  style: {
                    marginRight: "5px",
                  },
                  on: {
                    click: () => {
                      this.edit(JSON.stringify(params));
                    },
                  },
                },
                "编辑"
              ),
              h(
                "Button",
                {
                  props: {
                    type: "error",
                    size: "small",
                  },
                  on: {
                    click: () => {
                      this.openDel(params.row.id);
                    },
                  },
                },
                "删除"
              ),
            ]);
          },
        },
      ],
      tableData: [],
      tagList1: [],
      mainCode: [
        { name: "001MO", key: "mo001" },
        { name: "002MO", key: "mo002" },
        { name: "910GA", key: "ga001mo910" },
        { name: "910GA", key: "ga002mo910" },
        { name: "001MO电加热器", key: "moDptc001" },
        { name: "002MO电加热器", key: "moDptc002" },
        { name: "001MO循环水泵", key: "moPump001" },
        { name: "002MO循环水泵", key: "moPump002" },
        { name: "001MO预润滑油泵", key: "moOilPump001" },
        { name: "002MO预润滑油泵", key: "moOilPump002" },
        { name: "250CO启动次数", key: "coStartups250" },
        { name: "251CO启动次数", key: "coStartups251" },
        { name: "750CO启动次数", key: "coStartups750" },
        { name: "751CO启动次数", key: "coStartups751" },
        { name: "001MO预润滑流量限制阀", key: "moFlowValve001" },
        { name: "002MO预润滑流量限制阀", key: "moFlowValve002" },
        { name: "燃油储存罐001BA", key: "tank001ba" },
        { name: "燃油日用罐002BA", key: "fuel_tank002ba" },
        { name: "润滑油储存罐006BA", key: "storageTank006ba" },
        { name: "冷却水罐200BA", key: "coolingWater200ba" },
        { name: "冷却水罐700BA", key: "coolingWater700ba" },
        { name: "001MO A端入口油温", key: "moATemperature001" },
        { name: "001MO B端入口油温", key: "moBTemperature001" },
        { name: "002MO A端入口油温", key: "moATemperature002" },
        { name: "002MO B端入口油温", key: "moBTemperature002" },
        { name: "001MO 冷却水入口温度", key: "moCoolingInletTemp001" },
        { name: "001MO 冷却水出口温度", key: "moCoolingExitTemp001" },
        { name: "002MO 冷却水入口温度", key: "moCoolingInletTemp002" },
        { name: "002MO 冷却水出口温度", key: "moCoolingExitTemp002" },
        { name: "柴油机冷却剂入口压力", key: "dieselInletPressure200" },
        { name: "柴油机冷却剂入口压力", key: "dieselInletPressure700" },
        { name: "250/251/750/751BBA", key: "pressure" },
      ],
      option: {
        tooltip: {},
        legend: {
          data: [],
          top: "10",
          type: "scroll",
        },
        dataZoom: [],
        xAxis: {
          type: "time",
          axisLabel: {
            interval: 0,
            formatter: function(time) {
              const dateTime = new Date(time);
              const year = dateTime.getFullYear();
              const month =
                dateTime.getMonth() + 1 < 10
                  ? "0" + (dateTime.getMonth() + 1)
                  : dateTime.getMonth() + 1;
              const date =
                dateTime.getDate() < 10
                  ? "0" + dateTime.getDate()
                  : dateTime.getDate();
              const hour =  dateTime.getHours() + 1 < 10
                  ? "0" + (dateTime.getHours() + 1)
                  : dateTime.getHours() + 1;
              const minute = dateTime.getMinutes() < 10
                  ? "0" + dateTime.getMinutes()
                  : dateTime.getMinutes();
              const second = dateTime.getSeconds() < 10
                  ? "0" + dateTime.getSeconds()
                  : dateTime.getSeconds();
              return (
                year +
                "-" +
                month +
                "-" +
                date +
                " " +
                hour +
                ":" +
                minute +
                ":" +
                second
              );
            },
          },
        },
        yAxis: {
          name: "",
          type: "value",
        },
        series: [],
      },
      isChange: false,
    };
  },
  methods: {
    tabclick(e) {
      if (e == "tb1") {
        this.$router.push({ path: "testCheck" });
      } else {
        this.$router.push({ path: "testCheck2" });
      }
    },
    changeTime(e) {
      this.searchItem.startTime = e[0];
      this.searchItem.endTime = e[1];
      this.$echarts.init(document.getElementById("myChart")).dispose();

      this.tagList1 = [];
      this.option.legend.data = [];
      this.option.series = [];
      this.addJz();
    },
    download() {
      exp({ adminId:localStorage.getItem("recordUserId") }).then((res) => {
        const blob = new Blob([res], {
          type:
            "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;",
        });

        const ie = navigator.userAgent.match(/MSIE\s([\d.]+)/),
          ie11 =
            navigator.userAgent.match(/Trident\/7.0/) &&
            navigator.userAgent.match(/rv:11/),
          ieEDGE = navigator.userAgent.match(/Edge/g),
          ieVer = ie ? ie[1] : ie11 ? 11 : ieEDGE ? 12 : -1;
        console.log("ie:" + ie);
        console.log("ieVer:" + ieVer);
        if (ie && ieVer < 10) {
          this.message.error("No blobs on IE<10");
          return;
        }
        if (ieVer > -1) {
          window.navigator.msSaveBlob(blob, "启动前检查记录UD45.xlsx");
        } else {
          const url = window.URL.createObjectURL(blob);
          let link = document.createElement("a");
          link.setAttribute("href", url);
          link.setAttribute("download", "启动前检查记录UD45.xlsx");
          document.body.appendChild(link);
          link.click();
          document.body.removeChild(link);
        }
      });
    },
    fileSuccess(response, file, fileList) {
      this.$Message.info("导入成功");
      this.getDataList();
    },
    time(e) {
      this.formItem.checkTime = e;
    },
    handleClose1(event, name) {
      this.$echarts.init(document.getElementById("myChart")).dispose();
      const index = this.tagList1.indexOf(name);
      this.tagList1.splice(index, 1);
      this.option.legend.data.splice(index, 1);
      this.option.series.splice(index, 1);
      this.$echarts
        .init(document.getElementById("myChart"))
        .setOption(this.option);
    },
    addJz() {
      let that = this;
      if (this.tagList1.length > 9) {
        this.$Message.info("选择的对比已经很多了");
        return false;
      }
      if (this.searchItem.hdNumber == undefined) {
        this.$Message.info("请选择HD编号");
        return false;
      }
      if (this.searchItem.aircrewNumber == undefined) {
        this.$Message.info("请选择机组编号");
        return false;
      }
      echart(this.searchItem).then((res) => {
        if (res.code == 0 && res.data.length > 0) {
          let csname = that.mainCode.filter(
            (item) => item.key == that.searchItem.analyzeParam
          )[0].name;
          if (
            that.tagList1.indexOf(
              that.searchItem.aircrewNumber + "-" + csname
            ) == -1
          ) {
            that.tagList1.push(that.searchItem.aircrewNumber + "-" + csname);
            that.$echarts.init(document.getElementById("myChart")).dispose();
            that.option.legend.data.push(
              that.searchItem.aircrewNumber + "-" + csname
            );
            let sjcolor = that.color16();
            let arry = [];
            for (let n = 0; n < res.data.length; n++) {
              arry.push([
                res.data[n].checkTime,
                res.data[n][that.searchItem.analyzeParam],
              ]);
            }
            that.option.series.push({
              name: that.searchItem.aircrewNumber + "-" + csname,
              data: arry,
              type: "line",
              smooth: true,
              symbolSize: 8, //折线点的大小
              itemStyle: {
                normal: {
                  color: sjcolor, //折线点的颜色
                  lineStyle: {
                    color: sjcolor, //折线的颜色
                  },
                },
              },
            });
            that.$echarts.init(document.getElementById("myChart")).setOption(that.option);
          }
        } else {
          that.$Message.info("此选项下无数据！");
        }
      });
    },

    color16() {
      var n = Math.floor(Math.random() * this.colorarry.length + 1) - 1;
      return this.colorarry[n];
    },
    getDataList() {
      let that = this;
      that.tableData = [];
      getTableData({ pageNo: this.pageNo, pageSize: this.pageSize })
        .then((res) => {
          if (res.code == 0) {
            that.loading = false;
            that.total = res.data.total;
            that.tableData = res.data.list.sort(function(a, b) {
              return a.checkTime < b.checkTime ? 1 : -1;
            });

            that.allEquList2 = that.allEquList.filter(
              (item) => item.powerStation == res.data.list[0].powerStation
            );
            let arr2 = that.allEquList2.map(function(item) {
              return item.hdNumber;
            });
            that.HBnumberList = [...new Set(arr2)];

            let arr3 = that.allEquList2.filter(
              (item) => item.hdNumber == res.data.list[0].hdNumber
            );
            let arr4 = arr3.map(function(item) {
              return item.aircrewNumber;
            });
            that.JZnumberList = [...new Set(arr4)];

            that.searchItem.powerStation = res.data.list[0].powerStation;
            that.searchItem.hdNumber = res.data.list[0].hdNumber;
            that.searchItem.aircrewNumber = res.data.list[0].aircrewNumber;
          }
        })
        .catch((err) => {
          console.error("err>" + JSON.stringify(err));
        });
    },
    getAllEqument() {
      let that = this;
      getAllEqu(null).then((res) => {
        this.allEquList = res.data;
        let arr = res.data.map(function(item) {
          return item.powerStation;
        });
        this.powerStationList = [...new Set(arr)];
        this.getDataList();
        setTimeout(() => {
          that.addJz();
        }, 500);
      });
    },
    getHd(e) {
      this.JZnumberList = [];
      this.allEquList2 = this.allEquList.filter(
        (item) => item.powerStation == e
      );
      let arr2 = this.allEquList2.map(function(item) {
        return item.hdNumber;
      });
      this.HBnumberList = [...new Set(arr2)];
    },
    getJz(e) {
      let arr = this.allEquList2.filter((item) => item.hdNumber == e);
      let arr2 = arr.map(function(item) {
        return item.aircrewNumber;
      });
      this.JZnumberList = [...new Set(arr2)];
    },
    openDel(id) {
      this.delmodal1 = true;
      this.delID1 = id;
    },
    add() {
      this.formItem = {
        recordName: localStorage.getItem("recordUserName"),
        recordId: localStorage.getItem("recordUserId"),
        recordTime: getTime(),
      };
      this.isAdd = true;
      this.modal1 = true;
      this.modalTitle = "录入数据";
    },
    edit(params) {
      this.modalTitle = "编辑振动监测数据";
      this.formItem = JSON.parse(params).row;
      (this.formItem.recordName = localStorage.getItem("recordUserName")),
        (this.formItem.recordId = localStorage.getItem("recordUserId")),
        (this.formItem.recordTime = getTime());
      this.isAdd = false;
      this.modal1 = true;
      this.allEquList2 = this.allEquList.filter(
        (item) => item.powerStation == this.formItem.powerStation
      );
      let arr2 = this.allEquList2.map(function(item) {
        return item.hdNumber;
      });
      this.HBnumberList = [...new Set(arr2)];

      let arr3 = this.allEquList2.filter(
        (item) => item.hdNumber == this.formItem.hdNumber
      );
      let arr4 = arr3.map(function(item) {
        return item.aircrewNumber;
      });
      this.JZnumberList = [...new Set(arr4)];
    },
    timeFormat(time) {
      if (time instanceof Date == false) {
        return time;
      }
      const dateTime = new Date(time);
      const year = dateTime.getFullYear();
      const month = this.addZero(dateTime.getMonth() + 1);
      const date = this.addZero(dateTime.getDate());
      const hour = this.addZero(dateTime.getHours());
      const minute = this.addZero(dateTime.getMinutes());
      const second = this.addZero(dateTime.getSeconds());
      return (
        year +
        "-" +
        month +
        "-" +
        date +
        " " +
        hour +
        ":" +
        minute +
        ":" +
        second
      );
    },
    addZero(v) {
      return v < 10 ? "0" + v : v;
    },
    remove() {
      del({ id: this.delID1 })
        .then((res) => {
          if (res.code == 0) {
            this.$Message.info("删除成功");
            this.pageNo = 1;
            this.getDataList();
          } else {
            this.$Message.info(res.message);
          }
        })
        .catch((err) => {
          console.error("err>" + JSON.stringify(err));
        });
    },
    ok() {
      this.btnClick = true;
      if (this.isAdd) {
        add(this.formItem)
          .then((res) => {
            if (res.code == 0) {
              this.$Message.info("新增成功");
              this.getDataList();
              this.btnClick = false;
            } else {
              this.$Message.info(res.message);
            }
          })
          .catch((err) => {
            console.error("err>" + JSON.stringify(err));
          });
      } else {
        this.formItem.checkTime = this.timeFormat(this.formItem.checkTime);
        delete this.formItem._index;
        delete this.formItem._rowKey;
        update(this.formItem)
          .then((res) => {
            if (res.code == 0) {
              this.$Message.info("编辑成功");
              this.getDataList();
              this.btnClick = false;
            } else {
              this.$Message.info(res.message);
            }
          })
          .catch((err) => {
            console.error("err>" + JSON.stringify(err));
          });
      }
      this.modal1 = false;
    },
    /** 分页 */
    changePage(pageNo) {
      this.pageNo = pageNo;
      this.getDataList();
    },
  },
  created() {
    let mmtime = this.options2.shortcuts[2].value();
    this.searchItem.startTime = this.timeFormat(mmtime[0]);
    this.searchItem.endTime = this.timeFormat(mmtime[1]);
    this.timearry = this.options2.shortcuts[2].value();
    this.getAllEqument();
    // 基于准备好的dom，初始化echarts实例
    let myChart = this.$echarts.init(document.getElementById("myChart"));
    // 绘制图表
    myChart.setOption(this.option);
  },
};
</script>

<style lang="less">
.testCheck {
  background: #fff;
  height: 100%;
  padding: 15px;
  font-size: 14px;
  .ivu-tabs.ivu-tabs-card > .ivu-tabs-bar .ivu-tabs-tab {
    border-radius: 0;
    background: #fff;
    margin-right: 10px;
  }
  .ivu-tabs.ivu-tabs-card > .ivu-tabs-bar .ivu-tabs-tab-active {
    border-top: 2px solid #3399ff;
  }
  .ivu-tabs.ivu-tabs-card > .ivu-tabs-bar .ivu-tabs-tab-active:before {
    content: "";
    display: block;
    width: 100%;
    height: 1px;
    background: #3399ff;
    position: absolute;
    top: 0;
    left: 0;
  }
  .searchDiv {
    .marRight {
      margin-right: 15px;
    }
  }
  .ivu-form-item {
    margin-bottom: 15px;
  }
}
.baseTitle {
  font-weight: bold;
  font-size: 16px;
  margin-bottom: 10px;
}
.xzjz {
  .ivu-form-item {
    margin-bottom: 10px;
  }
}
.maintb {
  border-collapse: collapse;
}
.maintb td,
.maintb th {
  border: 1px solid #eaeaea;
  padding: 5px 10px;
  text-align: center;
}
.maintb th {
  background: #f5f5f5;
}
</style>
